//
//  CameraManDetailViewController.m
//  XDBaseFrameWork
//
//  Created by xindao on 14-9-22.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "CameraManDetailViewController.h"
#import "UIImageView+WebCache.h"
#import "TaoCanDetailViewController.h"
#import "CommentListViewController.h"
#import "WorksDetailViewController.h"
#import "CameramanTimeViewController.h"
#import "WorksDetailCell.h"
#import "MJPhoto.h"
#import "MJPhotoBrowser.h"
#import "Detail.h"

#import "SynthesizeDetailsViewController.h"

#import "ChooseTaoCanViewController.h"
#import "OrderSuccessViewController.h"

#define SHAREHEIGHT      205


@interface CameraManDetailViewController ()

@end

@implementation CameraManDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    self.titleLabel.text = @"摄影师详情";
    
    _EmplID = @"";
    _SeriesID = @"";
    _SceneID = @"";
    commentType = @"";
    page = 1;


    imageArray = [[NSMutableArray alloc] init];
    dataArray = [[NSMutableArray alloc] init];
    infoDict = [[NSMutableDictionary alloc] init];
    emplTimeArray = [[NSMutableArray alloc] init];
    commentCountDict = [[NSMutableDictionary alloc] init];
    
    float h1 = 0;
    float x = UI_SCREEN_WIDTH-94;
    if (IOS7) {
        h1 = 20;
    }
    
    UILabel * lab = [[UILabel alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH-50, h1+12, 38, 20)];
    lab.backgroundColor = UIColorFromRGB(0xff6000);
    lab.textColor = [UIColor whiteColor];
    lab.text = @"预约";
    lab.font = [UIFont systemFontOfSize:14.5];
    lab.textAlignment = NSTextAlignmentCenter;
    lab.layer.masksToBounds = YES;
    lab.layer.cornerRadius = 4;
    [self.navigationBarView addSubview:lab];
    
    UIButton * rightButton = [self createButtonOnNavigationWithRect:CGRectMake(UI_SCREEN_WIDTH-50, 0, 50, UI_NAVIGATION_BAR_HEIGHT) normalImg:nil highlightImg:nil];
    [rightButton addTarget:self action:@selector(rightButtonClick) forControlEvents:UIControlEventTouchUpInside];
    rightButton.backgroundColor = [UIColor clearColor];
    [self.navigationBarView addSubview:rightButton];
    
    UIButton * shareBtn = [UIButton initButton:CGRectMake(x, h1, 44, 44) btnNorImage:[UIImage imageNamed:@"share"] btnHighlightImage:nil btnTitle:nil titleColor:nil titleFont:nil];
    [shareBtn addTarget:self action:@selector(handleAlphaView) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationBarView addSubview:shareBtn];
    
    if (_distance) {
        x = UI_SCREEN_WIDTH-44;
        shareBtn.frame = CGRectMake(x, h1, 44, 44);
        rightButton.hidden = YES;
        lab.hidden = YES;
    }
    
    float h2 = 0;
    if (_distance) {
        h2 = UI_NAVIGATION_BAR_HEIGHT;
    }
    
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_MAINSCREEN_HEIGHT-UI_NAVIGATION_BAR_HEIGHT-h2) style:UITableViewStylePlain];
    myTableView.dataSource = self;
    myTableView.delegate = self;
    myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    myTableView.backgroundColor = UIColorFromRGB(0xf1f1f1);
    [self.contentView addSubview:myTableView];
    
    [myTableView addFooterWithTarget:self action:@selector(footerPulltoRefreshData)];
    [myTableView addHeaderWithTarget:self action:@selector(heaererPulltoRefreshData)];
    
    [self createBg1];
    
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing =0;
    flowLayout.minimumLineSpacing =3;
    flowLayout.headerReferenceSize = CGSizeMake(UI_SCREEN_WIDTH, 152/2.0);
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    flowLayout.sectionInset = UIEdgeInsetsMake(120,3,3,3);  //上左下右
    
    myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, UI_MAINSCREEN_HEIGHT-UI_NAVIGATION_BAR_HEIGHT-h2) collectionViewLayout:flowLayout];
    [myCollectionView registerClass:[WorksDetailCell class] forCellWithReuseIdentifier:@"cell"];
    myCollectionView.backgroundColor = UIColorFromRGB(0xf1f1f1);
    myCollectionView.alwaysBounceVertical = YES;
    myCollectionView.delegate = self;
    myCollectionView.dataSource = self;
//    myCollectionView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:myCollectionView];
    
    [self initShareView];
    
    if (workBtn.selected) {
        [myCollectionView addSubview:bg1];
        myTableView.hidden = YES;
//        [self getDetailDatas];
    }else{
        myTableView.tableHeaderView = bg1;
        myCollectionView.hidden = YES;
        [self getListDatas:1];
    }

//    if (_type) {
//        [self getDataWithDict:@{@"EmplID": _cameraManID} api:API_CAMERAMANDETAIL];
//    }else{
//        [self getDataWithDict:@{@"EmplID": _cameraManID,
//                                @"SceneID": [XDTools sharedXDTools].SceneID} api:API_CAMERAMANDETAIL];
//    }
    
    [self getDataWithDict:@{@"EmplID": _cameraManID} api:API_CAMERAMANDETAIL];
    
    [self getEmplTime];
}


#pragma mark  随意拍下单
-(void)addFreePaiOrder
{
    
    if (![XDTools NetworkReachable]) {
        [XDTools showTips:brokenNetwork toView:self.contentView];
        return;
    }
    
    NSDictionary * dict = @{@"SceneID":@"x9A71C3042DBC40BA8FCF0CECD49F97DFx",
                           @"CityID":BJcityID,
                           @"EmplID":_cameraManID};
    
    __weak ASIHTTPRequest *request = [XDTools postRequestWithDict:dict API:api_addCXOrder];
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        
        NSDictionary *tempDic = [XDTools  JSonFromString:[request responseString]];
        
        if([[tempDic objectForKey:@"status"] intValue] == 1){
            
            DDLOG(@"dic = %@",tempDic);
            
            [XDTools sharedXDTools].emplImgUrl = infoDict[@"EmplAvator"];
            [XDTools sharedXDTools].emplName = infoDict[@"EmplName"];
            [XDTools sharedXDTools].emplLevel = infoDict[@"LevelName"];
            
            OrderSuccessViewController * success = [[OrderSuccessViewController alloc] init];
            [self.navigationController pushViewController:success animated:YES];
            
            
        }else{
            [XDTools showTips:tempDic[@"msg"] toView:self.view];
            
        }
        
    }];
    
    [request setFailedBlock:^{
        [XDTools hideProgress:self.contentView];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}


#pragma mark
#pragma mark 预约摄影师
-(void)rightButtonClick
{
    if (_cameraManID) {
        [XDTools sharedXDTools].EmplID = _cameraManID;
    }
    
    if (_distance) {
        
        if (ISLOGING) {
            [self addFreePaiOrder];
        }else{
            loginViewController * loginVC = [[loginViewController alloc] init];
            [self.navigationController pushViewController:loginVC animated:YES];
        }
        
        
    }else{
        ChooseTaoCanViewController * chooseVC = [[ChooseTaoCanViewController alloc] init];
        chooseVC.type = 1;
        [self.navigationController pushViewController:chooseVC animated:YES];
        
        return;
        
        //type = 0 表示先选场景，type = 1 表示先选摄影师
        if (self.type == 0){
            if (ISLOGING){
                SynthesizeDetailsViewController * synDetailVC = [[SynthesizeDetailsViewController alloc] init];
                synDetailVC.isrenzheng = self.isRenZheng;
                [self.navigationController pushViewController:synDetailVC animated:YES];
            }else{
                loginViewController * loginVC = [[loginViewController alloc] init];
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            
            //单例存储用户信息
            //存储用户手机号
            [XDTools sharedXDTools].iphoneNumber = [[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_IPHONE];
            //存储用户ID
            [XDTools sharedXDTools].CustomerID = [[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_ID];
            //摄影师ID
            [XDTools sharedXDTools].EmplID = _cameraManID;
        }else{
            
        }

    }
    

    return;
    
    
}

-(void)getDataWithDict:(NSDictionary *)dict api:(NSString *)api
{

    if (![XDTools NetworkReachable]) {
        [XDTools showTips:brokenNetwork toView:self.contentView];
        return;
    }

    __weak ASIHTTPRequest *request = [XDTools postRequestWithDict:dict API:api];
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];

        NSDictionary *tempDic = [XDTools  JSonFromString:[request responseString]];

        if([[tempDic objectForKey:@"status"] intValue] == 1){

            DDLOG(@"dic = %@",tempDic);
            
            if ([api isEqualToString:API_CAMERAMANDETAIL]) {
                infoDict = [NSMutableDictionary dictionaryWithDictionary:tempDic[@"data"][@"EmplInfo"]];
                
                
                //值的存储 -- 摄影师
                [XDTools sharedXDTools].emplImgUrl = tempDic[@"data"][@"EmplInfo"][@"EmplAvator"];
                [XDTools sharedXDTools].emplLevel = tempDic[@"data"][@"EmplInfo"][@"LevelName"];
                [XDTools sharedXDTools].emplName = tempDic[@"data"][@"EmplInfo"][@"EmplName"];
                
                if ([tempDic[@"data"][@"EmplInfo"][@"IsCollection"] intValue]) {
                    isCollected = YES;
                    redHeart.image = [UIImage imageNamed:@"iscollection"];
                }else{
                    isCollected = NO;
                    redHeart.image = [UIImage imageNamed:@"nocollection"];
                }
                
                if(ARRAY_IS_NOT_EMPTY(tempDic[@"data"][@"EmplInfo"][@"ReviewTypeAvg"])){
                    [XDTools sharedXDTools].emplZhuanYe = [[tempDic[@"data"][@"EmplInfo"][@"ReviewTypeAvg"] firstObject] valueForKey:@"Avg"];
                    [XDTools sharedXDTools].emplGouTong = [[tempDic[@"data"][@"EmplInfo"][@"ReviewTypeAvg"] objectAtIndex:1] valueForKey:@"Avg"];
                    [XDTools sharedXDTools].emplShoushi = [[tempDic[@"data"][@"EmplInfo"][@"ReviewTypeAvg"] lastObject] valueForKey:@"Avg"];
                    
                }else{
                    [XDTools sharedXDTools].emplZhuanYe = nil;
                    [XDTools sharedXDTools].emplGouTong =nil;
                    [XDTools sharedXDTools].emplShoushi =nil;
                    
                }
                
                [self reloadViews];
                
            }else if ([api isEqualToString:API_COLLECT]){
                //（取消）收藏摄影师
                redHeart.image = [UIImage imageNamed:@"iscollection"];
                isCollected = YES;
                [XDTools showTips:@"收藏成功" toView:self.contentView];
                favNumberLB.text = [NSString stringWithFormat:@"%d",[favNumberLB.text intValue]+1];

                
                
            }else if ([api isEqualToString:API_cancellation]) {
                redHeart.image = [UIImage imageNamed:@"nocollection"];
                isCollected = NO;
                [XDTools showTips:@"取消收藏成功" toView:self.contentView];
                favNumberLB.text = [NSString stringWithFormat:@"%d",[favNumberLB.text intValue]-1];

            }

            

        }else{
            [XDTools showTips:tempDic[@"msg"] toView:self.view];

        }

    }];

    [request setFailedBlock:^{
        [XDTools hideProgress:self.contentView];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}


#pragma mark
#pragma mark 获取详情数据
-(void)getDetailDatas
{
    
    if (![XDTools NetworkReachable]){
        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    
    //SeriesID 套餐ID EmplID 摄影师ID  SceneID 场景ID
    NSDictionary * parms = @{@"SeriesID":self.SeriesID,
                             @"EmplID":self.cameraManID,
                             @"SceneID":self.SceneID};
    
    ASIHTTPRequest * request = [XDTools postRequestWithDict:parms API:works_detail];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            [imageArray addObjectsFromArray:tmpDict[@"data"][@"PhotoList"]];
            
            [myCollectionView reloadData];
            
//            //值的存储 -- 摄影师
//            [XDTools sharedXDTools].emplImgUrl = tmpDict[@"data"][@"EmplAvator"];
//            [XDTools sharedXDTools].emplLevel = tmpDict[@"data"][@"LevelName"];
//            [XDTools sharedXDTools].emplName =tmpDict[@"data"][@"EmplName"];
//            
//            if(ARRAY_IS_NOT_EMPTY(tmpDict[@"data"][@"ReviewTypeAvg"])){
//                
//                [XDTools sharedXDTools].emplZhuanYe = [[tmpDict[@"data"][@"ReviewTypeAvg"] firstObject] valueForKey:@"Avg"];
//                [XDTools sharedXDTools].emplGouTong =[[tmpDict[@"data"][@"ReviewTypeAvg"] objectAtIndex:1] valueForKey:@"Avg"];
//                [XDTools sharedXDTools].emplShoushi =[[tmpDict[@"data"][@"ReviewTypeAvg"] lastObject] valueForKey:@"Avg"];
//                
//            }else{
//                [XDTools sharedXDTools].emplZhuanYe = nil;
//                [XDTools sharedXDTools].emplGouTong =nil;
//                [XDTools sharedXDTools].emplShoushi =nil;
//            }
        }else{
            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        [XDTools hideProgress:self.contentView];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
}


#pragma mark 获取列表数据
-(void)getListDatas:(int)mPage
{
    if (![XDTools NetworkReachable]){
        
        page = page==1?(1):(page-1);
        
        [XDTools showTips:brokenNetwork toView:self.view];
        [myTableView headerEndRefreshing];
        [myTableView footerEndRefreshing];
        return;
    }
    
    if (self.EmplID == nil) {
        _EmplID = @"";
    }
    
    //page 页码 pageSize 每页数据条数  EmplID  摄影师id
    NSDictionary * parms = @{@"page":[NSString stringWithFormat:@"%d",mPage],
                             @"pageSize":@"10",
                             @"EmplID":self.cameraManID,
                             @"SeriesID":self.SeriesID,
                             @"Type":commentType};
    
    ASIHTTPRequest * request = [XDTools postRequestWithDict:parms API:API_GETCOMMENTS];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        
        [myTableView headerEndRefreshing];
        [myTableView footerEndRefreshing];
        
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            allCount = [[tmpDict valueForKey:@"Count"] intValue];
            if (page < 2){
                [dataArray removeAllObjects];
            }
//            if (!(ARRAY_IS_NOT_EMPTY(tmpDict[@"data"][@"List"]))){
//                [XDTools showTips:tmpDict[@"msg"] toView:self.view];
//                page = page==1?(1):(page-1);
//                [myTableView reloadData];
//                return;
//            }
            [dataArray addObjectsFromArray:tmpDict[@"data"][@"List"]];
            if (!dataArray.count) {
//                [XDTools showTips:@"暂无数据" toView:self.contentView];
            }
            commentCountDict = [NSMutableDictionary dictionaryWithDictionary:tmpDict[@"data"][@"TypeCount"]];
            [myTableView reloadData];
            
        }else{
            
            page = page==1?(1):(page-1);
            
//            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        
        page = page==1?(1):(page-1);
        
        [myTableView headerEndRefreshing];
        [myTableView footerEndRefreshing];
        
        [XDTools hideProgress:self.contentView];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    
    [request startAsynchronous];
    
}


- (UIView *)createBg1{
    bg1 = [UIView initViewRect:CGRectMake(0, 0, UI_SCREEN_WIDTH, 195) andBackGroudColor:[UIColor clearColor]];
    myTableView.tableHeaderView = bg1;
    
    UIView * bgbg1 = [UIView initViewRect:CGRectMake(0, 0, UI_SCREEN_WIDTH, 100) andBackGroudColor:[UIColor whiteColor]];
    [bg1 addSubview:bgbg1];
    
    redHeart = [[UIImageView alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH-37, 80, 22, 20)];
    redHeart.image = [UIImage imageNamed:@"nocollection"];
    [bgbg1 addSubview:redHeart];

    favNumberLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-42, height_y(redHeart)-2, 32, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:UIColorFromRGB(0xff6000) andTextAlignment:NSTextAlignmentCenter];
    [bgbg1 addSubview:favNumberLB];

    UIButton * btn = [UIButton initButton:CGRectMake(UI_SCREEN_WIDTH-55, 72, 55, 44) btnNorImage:nil btnHighlightImage:nil btnTitle:nil titleColor:nil titleFont:nil];
//    btn.backgroundColor = [UIColor orangeColor];
    [btn addTarget:self action:@selector(collectCameraMan) forControlEvents:UIControlEventTouchUpInside];
    [bgbg1 addSubview:btn];

    headIV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 27, 66, 66)];
    headIV.backgroundColor = UIColorFromRGB(0xeaeaea);
    headIV.layer.masksToBounds = YES;
    headIV.layer.cornerRadius = 33;
    headIV.userInteractionEnabled = YES;
    [bgbg1 addSubview:headIV];
    
    UITapGestureRecognizer *tapHeadIV = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headIVTaped)];
    tapHeadIV.numberOfTapsRequired = 1;
    [headIV addGestureRecognizer:tapHeadIV];
    

    nameLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(headIV)+12.5f, 16, 80, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:nameLB];
    
    if (_isRenZheng) {
        renzhengIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"renzheng"]];
        renzhengIV.frame = CGRectMake(VIEW_POINT_MAX_X(nameLB), 12, 0, 0);
        [bgbg1 addSubview:renzhengIV];
    }

    jibieLB = [UILabel initLabelText:@"" andRect:CGRectMake(nameLB.frame.origin.x, height_y(nameLB), 140, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:jibieLB];
    
    UILabel * qiLB = [UILabel initLabelText:@"起" andRect:CGRectMake(UI_SCREEN_WIDTH-22, 22, 16, 16) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:11] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:qiLB];

    priceLB = [UILabel initLabelText:@"" andRect:CGRectMake(nameLB.frame.origin.x, height_y(nameLB), 100, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:18] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    priceLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[@"0"] Color:RGBA(255, 116, 106, 1) Font:[UIFont systemFontOfSize:15] AllText:priceLB.text];
    [bgbg1 addSubview:priceLB];
    
    normalPriceLB = [UILabel initLabelText:@"" andRect:CGRectMake(UI_SCREEN_WIDTH-100, jibieLB.frame.origin.y, 100, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:normalPriceLB];

    numberLB = [UILabel initLabelText:@"" andRect:CGRectMake(nameLB.frame.origin.x, height_y(jibieLB), 100, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0xff6000) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:numberLB];

    distanceLB = [UILabel initLabelText:@"" andRect:CGRectMake(priceLB.frame.origin.x, 95, 150, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:12] andTextColor:RGBA(122, 110, 99, 1) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:distanceLB];
    
    line = [UIView initViewRect:CGRectMake(UI_SCREEN_WIDTH-6-[infoDict[@"MarketPrice"] length]*8, normalPriceLB.frame.origin.y+3, [infoDict[@"MarketPrice"] length]*8, 1) andBackGroudColor:UIColorFromRGB(0x828282)];
    [bgbg1 addSubview:line];
    
    if (!_distance) {
        jibieIV = [[UIImageView alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH-10-60, numberLB.frame.origin.y+4, 60, 12)];
        jibieIV.image = LOADIMAGE(@"seller-1-5@2x");
        [bgbg1 addSubview:jibieIV];

    }else{
        footView = [UIView initViewRect:CGRectMake(0, self.contentView.bounds.size.height-UI_NAVIGATION_BAR_HEIGHT, UI_SCREEN_WIDTH, UI_NAVIGATION_BAR_HEIGHT) andBackGroudColor:[UIColor whiteColor]];
        [self.contentView addSubview:footView];
        
        yuyueBtn = [UIButton initButton:CGRectMake(UI_SCREEN_WIDTH-111-10,7, 111,30) btnImage:nil btnTitle:@"预  约" titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:16]];
        [yuyueBtn addTarget:self action:@selector(rightButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:yuyueBtn];
        
        if ([_distance floatValue] > 1) {
            [yuyueBtn setImage:nil forState:UIControlStateNormal];
            [yuyueBtn setBackgroundColor:UIColorFromRGB(0xeaeaea)];
            yuyueBtn.titleLabel.textColor = UIColorFromRGB(0x999999);
            yuyueBtn.layer.masksToBounds = YES;
            yuyueBtn.layer.cornerRadius = 5;
            yuyueBtn.userInteractionEnabled = NO;
        }else{
            [yuyueBtn setBackgroundImage:LOADIMAGE(@"surexiadanbtn@2x") forState:UIControlStateNormal];
            [yuyueBtn setTitle:@"预  约" forState:UIControlStateNormal];
        }
    }
    
    UIImageView * shortXuXian = [[UIImageView alloc] initWithFrame:CGRectMake(85, height_y(numberLB)+2, 226, .5f)];
    shortXuXian.image = [UIImage imageNamed:@"xuxian_short"];
    [bgbg1 addSubview:shortXuXian];
    
    
    scoreLB = [UILabel initLabelText:@"" andRect:CGRectMake(numberLB.frame.origin.x, height_y(shortXuXian)+3, 180, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentLeft];
    [bgbg1 addSubview:scoreLB];

//    for (int i = 0; i < 5; i++) {
//        Detail * scoreView = [[Detail alloc] initWithFrame:CGRectMake(88+i*40, 64, 30, 30)];
//        scoreView.tag = 871270+i;
//        scoreView.hidden = YES;
//        [bgbg1 addSubview:scoreView];
//    }
    
    bgbg1.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH, height_y(distanceLB)+5);
    
//    float h = 0;
//    for (int i = 0; i < 3; i++) {
//        UILabel * lab = [UILabel initLabelText:@"" andRect:CGRectMake(84+i*63, height_y(distanceLB)+3, 28, 13) andBackGroudColor:UIColorFromRGB(0xf1f1f1) andTextFont:[UIFont boldSystemFontOfSize:11] andTextColor:UIColorFromRGB(0xb3b3b3) andTextAlignment:NSTextAlignmentCenter];
//        lab.layer.masksToBounds = YES;
//        lab.layer.cornerRadius = 6;
//        lab.tag = 87170+i;
//        [bgbg1 addSubview:lab];
//        
//        UILabel * scoreLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(lab), height_y(distanceLB)+3, 25, 15) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0x656565) andTextAlignment:NSTextAlignmentCenter];
//        scoreLB.tag = 87180+i;
//        [bgbg1 addSubview:scoreLB];
//        
//        h = height_y(scoreLB);
//
//    }
    
    
    


    UIView * bgbg2 = [UIView initViewRect:CGRectMake(0, height_y(bgbg1)+4, UI_SCREEN_WIDTH, 30) andBackGroudColor:[UIColor whiteColor]];
    [bg1 addSubview:bgbg2];
    
   
    workBtn = [UIButton initButton:CGRectMake(10, 0, 150, 30) btnNorImage:nil btnHighlightImage:nil btnTitle:@"作品" titleColor:UIColorFromRGB(0x666666) titleFont:[UIFont systemFontOfSize:15]];
    workBtn.backgroundColor = [UIColor clearColor];
    [workBtn setTitleColor:UIColorFromRGB(0x919191) forState:UIControlStateNormal];
    [workBtn setTitleColor:UIColorFromRGB(0xff6000) forState:UIControlStateSelected];
    [workBtn addTarget:self action:@selector(changeTabs:) forControlEvents:UIControlEventTouchUpInside];
    [bgbg2 addSubview:workBtn];
    
    
    commentBtn = [UIButton initButton:CGRectMake(VIEW_POINT_MAX_X(workBtn), 0, 150, 30) btnNorImage:nil btnHighlightImage:nil btnTitle:@"评价" titleColor:UIColorFromRGB(0x666666) titleFont:[UIFont systemFontOfSize:15]];
    commentBtn.backgroundColor = [UIColor clearColor];
    [commentBtn setTitleColor:UIColorFromRGB(0x919191) forState:UIControlStateNormal];
    [commentBtn setTitleColor:UIColorFromRGB(0xff6000) forState:UIControlStateSelected];
    [commentBtn addTarget:self action:@selector(changeTabs:) forControlEvents:UIControlEventTouchUpInside];
    [bgbg2 addSubview:commentBtn];
    
    UIView * lin = [UIView initViewRect:CGRectMake(159.5, 3, 1, 24) andBackGroudColor:UIColorFromRGB(0xd3d3d3)];
    [bgbg2 addSubview:lin];
    
    
    bg1.frame = CGRectMake(0, 0, UI_SCREEN_WIDTH, height_y(bgbg2));
    
    [self changeTabs:workBtn];
    
    return bg1;
}

- (void)changeTabs:(UIButton *)sender{
    if (sender == workBtn) {
        myTableView.tableHeaderView = nil;

        [myCollectionView addSubview:bg1];
        myTableView.hidden = YES;
        myCollectionView.hidden = NO;
        workBtn.selected = YES;
        commentBtn.selected = NO;
        if (!imageArray.count) {
            [self getDetailDatas];
        }
    }else{
//        [bg1 removeFromSuperview];
        myTableView.tableHeaderView = bg1;
        myTableView.hidden = NO;
//        [myTableView reloadData];
        myCollectionView.hidden = YES;
        workBtn.selected = NO;
        commentBtn.selected = YES;
        if (!dataArray.count) {
            [self getListDatas:1];
        }
    }
}

- (void)reloadViews{
    [headIV sd_setImageWithURL:[NSURL URLWithString:infoDict[@"EmplAvator"]] placeholderImage:LOADIMAGE(@"placeholderHeader@2x")];
    nameLB.text = infoDict[@"EmplName"];
    [nameLB sizeToFit];
    
    renzhengIV.frame = CGRectMake(VIEW_POINT_MAX_X(nameLB), 18, 14, 14);
    renzhengIV.hidden = NO;
    
    jibieLB.text = [NSString stringWithFormat:@"%@",infoDict[@"LevelName"]];
    priceLB.text = [NSString stringWithFormat:@"￥%@",infoDict[@"LowPrice"]];
    [priceLB sizeToFit];
    priceLB.frame=CGRectMake(UI_SCREEN_WIDTH-22-priceLB.bounds.size.width, 16, priceLB.bounds.size.width, priceLB.bounds.size.height);
//    priceLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[infoDict[@"LowPrice"]] Color:RGBA(255, 116, 106, 1) Font:[UIFont systemFontOfSize:15] AllText:priceLB.text];

    normalPriceLB.text = [NSString stringWithFormat:@"市场参考价 %@",infoDict[@"MarketPrice"]];
    [normalPriceLB sizeToFit];
    normalPriceLB.frame = CGRectMake(UI_SCREEN_WIDTH-normalPriceLB.bounds.size.width-10, jibieLB.frame.origin.y, normalPriceLB.bounds.size.width, normalPriceLB.bounds.size.height);
    
    line.frame = CGRectMake(UI_SCREEN_WIDTH-6-[infoDict[@"MarketPrice"] length]*8, normalPriceLB.frame.origin.y+7, [infoDict[@"MarketPrice"] length]*8, 1);
    
    favNumberLB.text = [NSString stringWithFormat:@"%@",infoDict[@"CollectionCount"]];
    numberLB.text = [NSString stringWithFormat:@"共接单%@次",infoDict[@"OrderCount"]];
    
    if (_distance) {
        distanceLB.text = [NSString stringWithFormat:@"距您%@公里",_distance];
        [distanceLB removeFromSuperview];
        distanceLB.frame = CGRectMake(10, 12, 100, 20);
        distanceLB.font = [UIFont systemFontOfSize:14];
        distanceLB.attributedText = [XDTools getAcolorfulStringWithTextArray:@[_distance] Color:UIColorFromRGB(0xf66000) Font:[UIFont systemFontOfSize:17] AllText:distanceLB.text];
        [distanceLB sizeToFit];
        [footView addSubview:distanceLB];
    }else{
        distanceLB.text = [NSString stringWithFormat:@"服务范围：%@",infoDict[@"FWCity"]];
    }
    
    NSMutableArray * scoreArray = [NSMutableArray arrayWithArray:infoDict[@"ReviewTypeAvg"]];
    if (scoreArray.count > 2) {
        scoreLB.text = [NSString stringWithFormat:@"%@ %@ %@ %@ %@ %@",scoreArray[0][@"ItemName"],scoreArray[0][@"Avg"],scoreArray[1][@"ItemName"],scoreArray[1][@"Avg"],scoreArray[2][@"ItemName"],scoreArray[2][@"Avg"]];

    }
    
    
    NSInteger num = [XDTools changeOrderCountToLevel:[infoDict[@"Score"]integerValue]];
    jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/5+1,num%5+1]];
    jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%5+1)*12, numberLB.frame.origin.y+4, (num%5+1)*12, 12);
    
//    int num = [infoDict[@"OrderCount"] intValue];
//    if (num >= 250) {
//        num = 249;
//    }else if (!num) {
//        num = 1;
//    }
//    jibieIV.image = [UIImage imageNamed:[NSString stringWithFormat:@"seller-%d-%d@2x",num/50+1,num%50/10+1]];
//    jibieIV.frame = CGRectMake(UI_SCREEN_WIDTH-10-(num%50/10+1)*12, numberLB.frame.origin.y+4, (num%50/10+1)*12, 12);

//    NSDictionary * dic1 = @{@"ItemName":@"单量",
//                            @"Avg":infoDict[@"OrderCount"]};
//    NSDictionary * dic2 = @{@"ItemName":@"收藏",
//                            @"Avg":infoDict[@"CollectionCount"]};
//    [scoreArray addObject:dic1];
//    [scoreArray addObject:dic2];
//    
//    for (int i = 0; i < 5; i++) {
//        Detail * scoreView = (Detail *)[bg1 viewWithTag:871270+i];
//        if (i < scoreArray.count) {
//            scoreView.hidden = NO;
//            [scoreView initDataWithDict:scoreArray[i]];
//        }else{
//            scoreView.hidden = YES;
//        }
//    }
    
    
    

}

- (void)collectCameraMan{
    if (!ISLOGING) {
        loginViewController * login = [[loginViewController alloc] init];
        [self.navigationController pushViewController:login animated:YES];
        return;
    }
    NSString * uid = [[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_ID];
    
    NSDictionary * dic = @{@"CustomerID":uid,
                           @"EmplID":_cameraManID,
                           @"Type":@"T"};
    
    if (isCollected) {
        [self getDataWithDict:dic api:API_cancellation];
    }else{
        [self getDataWithDict:dic api:API_COLLECT];
    }

}

////跳往  评论 界面

-(void)goToComments{
    CommentListViewController *listVC = [[CommentListViewController alloc] init];
    
    listVC.empleid = _cameraManID;
    listVC.seriesID = @"";
    [self.navigationController pushViewController:listVC animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//跳往摄影师 主页
-(void)headIVTaped
{
    CameraMameHomePageViewController *camerMameHomePage = [[CameraMameHomePageViewController alloc]init];
    camerMameHomePage.cameraManId = _cameraManID;
    camerMameHomePage.cameraHeaderImage = headIV.image;
    camerMameHomePage.cameraManName = nameLB.text;
    [self.navigationController pushViewController:camerMameHomePage animated:YES];
}

#pragma mark
#pragma mark 获取摄影师时间表数据源
-(void)getEmplTime
{
    if (![XDTools NetworkReachable]){
//        [XDTools showTips:brokenNetwork toView:self.view];
        return;
    }
    ASIHTTPRequest * request = [XDTools postRequestWithDict:@{@"EmplID":_cameraManID} API:API_getEmplTime];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            [emplTimeArray removeAllObjects];
            if (ARRAY_IS_NOT_EMPTY(tmpDict[@"data"][@"EmplUsedTime"])){
                [emplTimeArray addObjectsFromArray:tmpDict[@"data"][@"EmplUsedTime"]];
            }
        }else{
            [XDTools showTips:tmpDict[@"msg"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        [XDTools hideProgress:self.view];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
}

#pragma mark
#pragma mark loginViewControllerDelegate
-(void)lReflashData
{
//    if (_type) {
//        [self getDataWithDict:@{@"EmplID": _cameraManID} api:API_CAMERAMANDETAIL];
//    }else{
//        [self getDataWithDict:@{@"EmplID": _cameraManID,
//                                @"SceneID": [XDTools sharedXDTools].SceneID} api:API_CAMERAMANDETAIL];
//    }
    [self getDataWithDict:@{@"EmplID": _cameraManID} api:API_CAMERAMANDETAIL];

}


#pragma mark UICollectionView Delegate
//设置分区
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

//每个分区上的元素个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [imageArray count];
}

//设置元素内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"cell";
    WorksDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

    NSDictionary * dict = [imageArray objectAtIndex:indexPath.row];
    
    [cell.imageIV sd_setImageWithURL:[NSURL URLWithString:[dict valueForKey:@"Photo"]] placeholderImage:ivDetaultImg];
    
    return cell;
}

//设置元素的的大小框
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UIEdgeInsets top ={82,5,3,5};
    return top;
}



//设置元素大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(100,100);
}

//点击元素触发事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
//    WorksDetailCell * cell = (WorksDetailCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if([imageArray  count]){
        int count = imageArray.count;
        // 1.封装图片数据
        NSMutableArray * photos = [NSMutableArray arrayWithCapacity:count];
        for (int i = 0; i<count; i++) {
            // 替换为中等尺寸图片
            NSString *url = imageArray[i][@"Photo"];
            MJPhoto * photo = [[MJPhoto alloc] init];
            photo.url = [NSURL URLWithString:url]; // 图片路径
//            photo.srcImageView = cell.imageIV;
            [photos addObject:photo];
            
        }
        
        // 2.显示相册
        MJPhotoBrowser * browser = [[MJPhotoBrowser alloc] init];
        browser.currentPhotoIndex = indexPath.row;
        browser.photos = photos; // 设置所有的图片
        [browser show];
    }
    
}


#pragma mark - TableView DataSource
#pragma  tableview 代理方
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [dataArray count]+1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!indexPath.row) {
        NSString * cellIde = @"cell0";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIde];
        
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIde];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.contentView.backgroundColor = [UIColor clearColor];
            cell.backgroundColor = [UIColor clearColor];
            
            
            
            DLStarRatingControl * starView = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(UI_SCREEN_WIDTH/2-70,5,120, 20) andStars:5 isFractional:YES];
            
            starView.backgroundColor = [UIColor clearColor];
            starView.rating = 0;
            starView.enabled = NO;
            starView.tag = 12345;
            [cell.contentView addSubview:starView];
            
            UILabel * mainScoreLB = [UILabel initLabelText:@"" andRect:CGRectMake(VIEW_POINT_MAX_X(starView), 8, 40, 20) andBackGroudColor:[UIColor clearColor] andTextFont:[UIFont systemFontOfSize:16] andTextColor:UIColorFromRGB(0xff6000) andTextAlignment:NSTextAlignmentLeft];
            mainScoreLB.tag = 123456;
            [cell.contentView addSubview:mainScoreLB];
            
            
            
            NSArray * arr = @[@"全部",@"有图",@"好评",@"中评",@"差评"];
            for (int i = 0; i < 5; i++) {
                UIButton * btn = [UIButton initButton:CGRectMake(4+63*i, height_y(mainScoreLB)+4, 60, 20) btnNorImage:nil btnHighlightImage:nil btnTitle:arr[i] titleColor:[UIColor whiteColor] titleFont:[UIFont systemFontOfSize:12]];
                if (!i) {
                    [btn setBackgroundColor:UIColorFromRGB(0xff6800)];
                }else{
                    [btn setBackgroundColor:UIColorFromRGB(0xb3b3b3)];
                }
                btn.layer.masksToBounds = YES;
                btn.layer.cornerRadius = 5;
                btn.tag = 812770+i;
                [btn addTarget:self action:@selector(changeCommentList:) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:btn];
            }
            
            
        }
        
        if (commentCountDict.count) {
            NSArray * arr = @[@"全部",@"有图",@"好评",@"中评",@"差评"];
            NSArray * keys = @[@"T",@"H",@"Z",@"C"];
            for (int i = 0; i < 5; i++) {
                UIButton * btn = (UIButton *)[cell.contentView viewWithTag:812770+i];
                if (!i) {
                    [btn setTitle:[NSString stringWithFormat:@"%@(%d)",arr[i],[commentCountDict[keys[1]] intValue]+[commentCountDict[keys[2]] intValue]+[commentCountDict[keys[3]] intValue]] forState:UIControlStateNormal];
                }else{
                    [btn setTitle:[NSString stringWithFormat:@"%@(%@)",arr[i],commentCountDict[keys[i-1]]] forState:UIControlStateNormal];
                }
            }
            
            DLStarRatingControl * star = (DLStarRatingControl *)[cell.contentView viewWithTag:12345];
            star.rating = [infoDict[@"ReviewAvg"] floatValue];
            
            UILabel * label = (UILabel *)[cell.contentView viewWithTag:123456];
            label.text = infoDict[@"ReviewAvg"];

        }
        
        return cell;
    }else{
        NSString *cellIdentifer = @"commentCell";
        
        CommentsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
        
        if (!cell) {
            cell = [[CommentsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        cell.delegate = self;
        cell.dataDict = [dataArray objectAtIndex:indexPath.row-1];
        
        return cell;
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row) {
        if (!testLB) {
            testLB = [[UILabel alloc] init];
            testLB.numberOfLines = 0;
            testLB.font = [UIFont systemFontOfSize:15];
        }
        
        testLB.frame = CGRectMake(0, 0, 300, 23);
        testLB.text = [[dataArray objectAtIndex:indexPath.row-1] valueForKey:@"ReviewContent"];
        [testLB sizeToFit];
        if ([[[dataArray objectAtIndex:indexPath.row-1] valueForKey:@"ReviewPhoto"] count]){
            return 10+50+10+testLB.bounds.size.height+20+70+20;
        }
        
        return 10+50+10+testLB.bounds.size.height+20;
    }else{
        return 60;
    }
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

#pragma mark - 查看不同类别评论
- (void)changeCommentList:(UIButton *)sender{
    NSArray * arr = @[@"",@"T",@"H",@"Z",@"C"];
    for (int i = 0; i < 5; i++) {
        UIButton * btn = (UIButton *)[self.view viewWithTag:812770+i];
        [btn setBackgroundColor:UIColorFromRGB(0xb3b3b3)];
        if (sender == btn) {
            commentType = arr[i];
            page =1;
            [self getListDatas:1];
        }
    }
    
    [sender setBackgroundColor:UIColorFromRGB(0xff6800)];

}

#pragma mark
#pragma mark CommentsTableViewCellDelegate
-(void)chooseImageView:(UIImageView *)iv andIvArray:(NSArray *)ivArray andImageUrlArray:(NSArray *)mImageUrlArray
{
    if (ARRAY_IS_NOT_EMPTY(mImageUrlArray)){
        int count = mImageUrlArray.count;
        NSMutableArray * photos = [NSMutableArray arrayWithCapacity:count];
        for (int i = 0; i<count; i++) {
            NSString *url = mImageUrlArray[i];
            MJPhoto * photo = [[MJPhoto alloc] init];
            photo.url = [NSURL URLWithString:url]; // 图片路径
            photo.srcImageView = [ivArray objectAtIndex:i];
            [photos addObject:photo];
        }
        
        // 2.显示相册
        MJPhotoBrowser * browser = [[MJPhotoBrowser alloc] init];
        browser.currentPhotoIndex = iv.tag-1000;
        browser.photos = photos; // 设置所有的图片
        [browser show];
    }
}



#pragma mark  =======上下拉刷新========

-(void)heaererPulltoRefreshData
{
    page = 1;
    [self getListDatas:1];
}

-(void)footerPulltoRefreshData
{
    if (1) {
        page++;
        [self getListDatas:page];
    }else{
        if (1) {
            myTableView.footerRefreshingText = @"没有更多数据...";
            [self performSelector:@selector(delayToEndRefreshLoading) withObject:nil afterDelay:.5f];
        }
    }
}
-(void)delayToEndRefreshLoading
{
    [myTableView footerEndRefreshing];
    myTableView.footerRefreshingText = @"正在加载数据";
}

//初始化分享view
-(void)initShareView{
    
    
    window = [[[UIApplication sharedApplication] delegate] window];
    aliphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, window.frame.size.height)];
    aliphaView.backgroundColor = [UIColor blackColor];
    aliphaView.alpha = .2f;
    aliphaView.hidden = YES;
    [window addSubview:aliphaView];
    
    UITapGestureRecognizer *alphaTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleAlphaView)];
    [aliphaView addGestureRecognizer:alphaTap];
    
    shareView = [[UIView alloc] initWithFrame:CGRectMake(0,window.frame.size.height , window.frame.size.width, SHAREHEIGHT)];
    shareView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"shareView_back"]];
    
    
    UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(138, 12, 52, 18)];
    shareLabel.backgroundColor = [UIColor clearColor];
    shareLabel.font = [UIFont systemFontOfSize:17];
    shareLabel.text = @"分享到";
    shareLabel.textColor = UIColorFromRGB(0x999999);
    [shareView addSubview:shareLabel];
    
    [window addSubview:shareView];
    
    
    
    
    
    
    for (int i = 0; i<3; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(35+(60+35)*(i%4), 48+(i/4)*(18+8+20+60), 60, 60);
        button.tag = 100+i;
        [button addTarget:self action:@selector(goToShare:) forControlEvents:UIControlEventTouchUpInside];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.origin.x, button.frame.origin.y+button.frame.size.height+8, 60, 18)];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont systemFontOfSize:15];
        label.textColor = UIColorFromRGB(0x666666);
        label.textAlignment = NSTextAlignmentCenter;
        
        [shareView addSubview:button];
        [shareView addSubview:label];
        
        switch (i) {
            case 0:
            {
                [button setBackgroundImage:[UIImage imageNamed:@"weibo_icon"] forState:UIControlStateNormal];
                label.text = @"新浪微博";
            }
                break;
            case 1:
            {
                [button setBackgroundImage:[UIImage imageNamed:@"weixin_icon"] forState:UIControlStateNormal];
                label.text = @"微信";
            }
                break;
            case 2:
            {
                [button setBackgroundImage:[UIImage imageNamed:@"friend_cycle"] forState:UIControlStateNormal];
                label.text = @"朋友圈";
            }
                break;
                
            default:
                break;
        }
        
    }
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(16, shareView.frame.size.height-15-39, 288, 39);
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"cancel_share"] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(handleAlphaView) forControlEvents:UIControlEventTouchUpInside];
    
    [shareView addSubview:cancelBtn];
    
    
    
}




//////分享回调方法
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSString *type = [[response.data allKeys] objectAtIndex:0];
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
        
        //wxsession  wxtimeline  sina
        [XDTools showTips:@"分享成功" toView:self.contentView];
    }
}


//去分享
-(void)goToShare:(UIButton *)button{
    
    BOOL isAccessSina = [UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToSina];
    
    BOOL isAccessQQ = [UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToQQ];
    
    BOOL isAccessQQZone = [UMSocialAccountManager isOauthAndTokenNotExpired:UMShareToQzone];
    
    NSString *qqShareType;
    BOOL qqOauth;
    
    UIImage *shareImage;
    if (shareIm == nil) {
        shareImage = [UIImage imageNamed:@"Icon_ios7"];
    }else{
        shareImage = shareIm;
    }
    
    
    [self handleAlphaView];
    int tag = button.tag - 100;
    
    
    [UMSocialData defaultData].extConfig.title = @"儿童摄影，就找小鬼当佳！";
    
    //设置分享内容和回调对象
    if (tag == 0){
        
        if (shareIm == nil) {
            shareImage = [UIImage imageNamed:@"Icon_ios7"];
        }
        
        [[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"我家宝贝在小鬼当佳拍照了，找的就是摄影师%@，很不错哦！",nameLB.text] shareImage:shareImage socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        
    }else if (tag == 1){
        //微信会话
        
        [UMSocialData defaultData].extConfig.wechatSessionData.url = [NSString stringWithFormat:@"http://www.meike365.cn/index.php?m=Api&c=Wap&a=index&EmplID=%@",_cameraManID]; //设置你自己的url地址;
        
        
        
        [[UMSocialControllerService defaultControllerService] setShareText:[NSString stringWithFormat:@"我家宝贝在小鬼当佳拍照了，找的就是摄影师%@，很不错哦！",nameLB.text] shareImage:shareImage socialUIDelegate:self];
        UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
        snsPlatform.snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        
        
    }else if (tag == 2){
        //朋友圈分享
        [UMSocialData defaultData].extConfig.title = [NSString stringWithFormat:@"我家宝贝在小鬼当佳拍照了，找的就是摄影师%@，很不错哦！",nameLB.text];
        
        NSString * url = [NSString stringWithFormat:@"http://www.meike365.cn/index.php?m=Api&c=Wap&a=index&EmplID=%@",_cameraManID];
        
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = [NSString stringWithFormat:@"http://www.meike365.cn/index.php?m=Api&c=Wap&a=index&EmplID=%@",_cameraManID]; //设置你自己的url地址;
        
        [[UMSocialControllerService defaultControllerService] setShareText:nil shareImage:shareImage socialUIDelegate:self];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
    }
}




#pragma mark 分享
- (void)handleAlphaView{
    if (aliphaView.hidden) {
        aliphaView.hidden = NO;
        [UIView animateWithDuration:.3 animations:^{
            
            shareView.frame = CGRectMake(0,window.frame.size.height-SHAREHEIGHT , window.frame.size.width, SHAREHEIGHT);
            
            
        }];
    }else{
        aliphaView.hidden = YES;
        [UIView animateWithDuration:.3 animations:^{
            shareView.frame = CGRectMake(0,window.frame.size.height , window.frame.size.width, SHAREHEIGHT);
        }];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
